{% extends "personal_center/base.html" %}

{% block page_link %}
    <link rel="stylesheet" href="../../static/system_setup/css/style.css">
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }
        tr {
            height: 35px;
        }
        th {
            text-align: center;
        }
        td:first-child, th:first-child {
            position: sticky;left: 0;z-index: 1;
        }
        thead tr th {
            position: sticky;top: 0;background-color: #E8E8E8;
        }
        th:first-child {
            z-index: 2;
        }
        #tb_1 tr:hover {
            background: #cfcfcf;
        }
        .file {
            position: relative;display: inline-block;background: #D0EEFF;border: 1px solid #99D3F5;border-radius: 4px;padding: 4px 12px;overflow: hidden;color: #1E88C7;text-decoration: none;text-indent: 0;line-height: 20px;
        }
        .file input {
            position: absolute;font-size: 100px;right: 0;top: 0;opacity: 0;
        }
        .file:hover {
            background: #AADFFD;border-color: #78C3F3;color: #004974;text-decoration: none;
        }
        .search {
            width: 300px;display: flex;float: right;margin: 10px 0;margin-right: 1%;
        }
        .search input {
            vertical-align: middle;float: left;height: 30px;width: 230px;outline: none;border: 1px solid #0070c1;box-sizing: border-box;border-bottom-left-radius: 3px;border-top-left-radius: 3px;
        }
        .search button {
            float: right;flex: 1;height: 30px;width: 70px;line-height: 30px;background-color: #0070c1;color: white;border-style: none;outline: none;border-bottom-right-radius: 3px;border-top-right-radius: 3px;
        }
        .search button i {
            font-style: normal;
        }
        .search button:hover {
            font-size: 16px;
        }
        .check_anniu {
            cursor: pointer;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <span> 用印申请</span>
            </a>
        </div>
        <div style="height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="save_data()">
                保存
            </button>
        </div>
        <div style="width: 7%;text-align: center;height: 100%;line-height: 40px;float: right;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 30px;"
                    onclick="ExportCar()">
                提交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95.5%;overflow: auto;">
        <div id="menu_from"
             style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;">
            <div style="width: 80%;height: 90%;display: inline-block;vertical-align: center;margin-left: 10%;margin-top: 15px;">
                <div style="width: 95%;margin-left: 2.5%;">
                    <table style="width: 100%;">
                        <tr>
                            <td colspan="4" style="width: 100%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">
                                <h3 id="form_name" style="text-align: center;">印章/重要证件使用(借用)审批单</h3>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" style="width: 100%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #F5F5F5;border: #cfcfcf solid 0.5px;">
                                用印信息
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;padding-right: 1%;">
                                申&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;人
                            </td>
                            <td id="applicat"
                                style="width: 35%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;">
                                {{ realname }}
                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;padding-right: 1%;">
                                申请日期
                            </td>
                            <td id="now_time"
                                style="width: 35%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ now_date }}</td>
                        </tr>

                        <tr style="width: 100%;">
                            <td style="width: 15%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;padding-right: 1%;">
                                用&nbsp;&nbsp;&nbsp;印&nbsp;&nbsp;&nbsp;事&nbsp;&nbsp;由
                            </td>
                            <td id="yysy_fill" style="width: 35%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 1%;">
                                {% if Quick == 'true' %}
                                    <select name="" id="yysy" style="width: 100%;height: 100%;border: none;outline: none;" onchange="OrNotFill()">
                                        <option value="-1">请选择快捷用印事由</option>
                                        {% for str in str_list %}
                                            <option value="{{ str }}">{{ str }}</option>
                                        {% endfor %}
                                        <option value="其他">其他</option>
                                    </select>
                                {% else %}
                                    <div id="yysy" style="width: 100%;height: 100%;border: none;outline: none;" contenteditable="true"></div>
                                {% endif %}
                            </td>
                            <td style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;padding-right: 1%;">
                                用印次数
                            </td>
                            <td style="width: 35%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;">
                                <input type="number" id="fenshu" style="width: 100%;height: 35px;line-height: 35px;padding-left: 2%;border:none;outline: none;" autocomplete="off">
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 15%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;border-top: none;text-align: right;padding-right: 1%;">
                                分&nbsp;&nbsp;&nbsp;管&nbsp;&nbsp;&nbsp;领&nbsp;&nbsp;导
                            </td>
                            <td style="height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;border-top: none;outline: none;padding-left: 1%;width: 35%;" id="leader_charge">
                                <select name="" id="leader_select" style="width: 100%;height: 100%;border: none;outline: none;">
                                    <option value="">请选择分管领导</option>
                                    {% for foo in leaders_obj %}
                                        <option value="{{ foo.id }}">{{ foo.real_name }}</option>
                                    {% endfor %}
                                </select>
                            </td>
                            <td style="width: 15%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;border-top: none;text-align: right;padding-right: 1%;">
                                文件类型
                            </td>
                            <td style="height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;border-top: none;outline: none;padding-left: 1%;width: 35%;" id="leader_charge">
                                <select name="" id="FileType" style="width: 100%;height: 100%;border: none;outline: none;">
                                    <option value="0">请选择文件类型</option>
                                    <option value="1">协议类</option>
                                    <option value="2">非协议类</option>
                                </select>
                            </td>
                        </tr>
                        <tr id="yy_detail" style="display: none;">
                            <td style="height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;border-top: none;text-align: right;padding-right: 1%;">
                                用&nbsp;&nbsp;&nbsp;印&nbsp;&nbsp;&nbsp;详&nbsp;&nbsp;情
                            </td>
                            <td style="height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;border-top: none;outline: none;padding-left: 1%;" colspan="3" id="leader_charge">
                                <div id="YDetail" style="width: 100%;height: 100%;border: none;outline: none;" contenteditable="true"></div>
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td id="NameOfSeal" style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;border-top: none;padding-right: 1%;">
                                印章/证件名称
                            </td>
                            <td id="NameOfSealInput" colspan="3" style="width: 85%;height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;border-top: none;position: relative;font-size: 0;">
                                <div onclick="myclick1()" id="selectButton_1" style="width:100%;height:100%;font-size:14px;border: none;padding-left: 1%;"></div>
                                <div id="selectdiv_1" style="display:none;width:100%;font-size:14px;position: absolute;background: white;z-index: 3000;border: #cfcfcf solid 0.5px;" onMouseOver="mousein1()" onMouseOut="mouseout1()">
                                    {% for seal in seal_obj %}
                                        <input class="check_anniu" style="margin-left: 0.5%;" type="checkbox" value="{{ seal.seal_name }}" onclick="mycheck1(this)"> {{ seal.seal_name }}<br>
                                    {% endfor %}
                                </div>
                            </td>
                            <td id="CertificateName" style="width: 15%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;border-top: none;padding-right: 1%;display: none;">
                                证件名称
                            </td>
                            <td id="CertificateNameInput" style="width: 35%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;border-top: none;display: none;">
                                <input id="zjmc" type="text" style="width: 100%; height: 100%;border: none;padding-left: 1%;" autocomplete="off">
                            </td>
                        </tr>
                        <tr style="width: 100%;">
                            <td style="width: 15%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;padding-right: 1%;">
                                备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注
                            </td>
                            <td style="height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;border-top: none;outline: none;padding-left: 1%;" colspan="3" id="note" contenteditable="true"></td>
                        </tr>
                        {% if bgs_flag == 'true' %}
                            <tr style="width: 100%;">
                                <td style="width: 15%;border-right: #cfcfcf solid 0.5px;border-left: #cfcfcf solid 0.5px;border-bottom: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;text-align: right;padding-right: 1%;">
                                    线&nbsp;&nbsp;&nbsp;下&nbsp;&nbsp;&nbsp;用&nbsp;&nbsp;印
                                </td>
                                <td style="height: 35px;line-height: 35px;border: #cfcfcf solid 0.5px;border-top: none;outline: none;padding-left: 1%;" colspan="3">
                                    <input type="radio" name="offline" value="1"> 是
                                    <input type="radio" name="offline" value="0" style="margin-left: 20px;" checked> 否
                                </td>
                            </tr>
                        {% endif %}
                    </table>
                </div>
                <div style="width: 95%;margin-left: 2.5%;">
                    <div style="width: 100%;height: 40px;line-height: 40px;background-color: #F5F5F5;color: #1E90FF;padding-left: 1%;border: #cccccc solid 1px;border-top: none;border-bottom: none;padding-right: 1%;">
                        上传附件<span style="font-size: 10px; color: red">（注意！需要盖章的文件必须上传附件！）</span>
                        <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                            上传文件
                            <input type="file" name="party_main_body" id="party_main_body"
                                   onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                        </a>
                    </div>
                    <table style="width: 100%;">
                        <thead>
                        <tr>
                            <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件名称
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件大小
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传时间
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传人员
                            </td>
                            <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                            </td>
                        </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="party_main"></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div id="del_adjunct"
         style="z-index: 1000;position: fixed;background-color: rgba(36, 36, 36, 0.5);width: 100%;height: 100%;top: 0;left: 0;right: 0;bottom: 0;display: none;">
        <div style="top: 50%;left: 50%;width: 400px;height: 150px;background: white;transform:translate(-50%,-50%);border: #dfdfdf solid 1px;position: absolute;border-radius: 4px;">
            <div style="width: 100%;height: 100px;text-align: center;line-height: 100px;">请查看附件，删除无用的附件！</div>
            <hr>
            <div style="width: 100%;height: 50px;text-align: right;padding-right: 5%;">
                <button onclick="del_adjunct_button()"
                        style="width: 50px;height: 30px;line-height: 30px;margin-top: 10px;background: #00a0e9;color: white;border-radius: 4px;border: #00a0e9 solid 1px;">
                    确认
                </button>
            </div>
        </div>
    </div>
{% endblock %}

{% block script %}
    <script src="../../static/system_setup/creat_from/js/jquery-1.10.2.js"></script>
    <script>
        window.onload = function () {
            document.getElementById("loading").style.display = "none";
            document.getElementById("personage").className = "add_class";
            document.getElementById("sponsor").className = "add-nav-active";
        };
        var Quick = "{{ Quick | safe }}";
        const uuid = "{{ uuid | safe }}"
        var initlist = [];
        var SealList = {{ SealList | safe }};
        var JudgmentDictionary = {{ JudgmentDictionary | safe }};
        department = "{{ department | safe }}";
        selectedlist1 = [];
        selectednamelist1 = [];

        function myclick1() {
            var selecteddiv = document.getElementById("selectdiv_1");
            selecteddiv.style.display = "inline-block";
        }

        function mousein1() {
            var selecteddiv = document.getElementById("selectdiv_1");
            selecteddiv.style.display = "inline-block";
        }

        //鼠标离开多选框的div【selectdiv】
        function mouseout1() {
            var selecteddiv = document.getElementById("selectdiv_1");
            selecteddiv.style.display = "none";
        }

        //checkbox的点击事件
        function mycheck1(obj) {
            if (Quick === "true") {
                if (document.getElementById("yysy").value !== "其他") {
                    var chose_seal_name = JudgmentDictionary[document.getElementById("yysy").value];
                    if (chose_seal_name.indexOf(obj.value) === -1) {
                        alert("该用印事由的快捷用印，只能选择 ”" + chose_seal_name + "“！若需要选择该印章，可选择“其他”，并填写用印详情！")
                        obj.checked = false;
                        return false
                    }
                }
            }

            // 判断印章名称里面有没有其他类型
            if (obj.value === '其他证书') {
                if (obj.checked) {
                    document.getElementById('NameOfSealInput').style.width='35%';
                    document.getElementById('NameOfSealInput').removeAttribute('colspan');
                    document.getElementById('CertificateName').style.display='table-cell';
                    document.getElementById('CertificateNameInput').style.display='table-cell'
                }else {
                    document.getElementById('CertificateName').style.display='none';
                    document.getElementById('CertificateNameInput').style.display='none'
                    document.getElementById('NameOfSealInput').style.width='85%';
                    document.getElementById('NameOfSealInput').setAttribute('colspan', '3');
                }
             }
            var checked_list = document.getElementsByClassName("check_anniu");
            var checked_value = []
            for (var t = 0; t < checked_list.length; t++) {
                if (checked_list[t].checked) {
                    checked_value.push(checked_list[t].value)
                }
            }
            document.getElementById("selectButton_1").innerText = checked_value.join(", ");
            var QuickApplication = $("input[type=radio][name=QuickApplication]:checked").val();
            if (QuickApplication === 'yes') {
                var form = new FormData();
                form.append("checked_value", JSON.stringify(checked_value));
                var xhr = new XMLHttpRequest();
                var local_host = window.location.host;          // 获取当前IP
                xhr.open('post', "/system-setup/QueryAuthorization", true);
                xhr.send(form);
                xhr.onreadystatechange = function () {
                    if (xhr.readyState === 4) {
                        if (xhr.status === 200) {
                            document.getElementById("loading").style.display = "none";
                            var JsonDate = JSON.parse(xhr.responseText);
                            console.log(JsonDate);
                            var shouquan_type = document.getElementById("shouquan_type")
                            shouquan_type.innerHTML=""
                            for (var i=0; i<JsonDate["data"].length; i++) {
                                var p_tag = document.createElement('p');
                                var input_tag = document.createElement("input");
                                var span_tag = document.createElement("span");
                                input_tag.type="checkbox";input_tag.className="shouquantype";input_tag.value=JsonDate["data"][i]["id"];
                                span_tag.innerHTML=JsonDate["data"][i]["category"];
                                p_tag.appendChild(input_tag);p_tag.appendChild(span_tag);shouquan_type.appendChild(p_tag);
                            }
                            document.getElementById("shouquan_tr").style.display='table-row';
                        }
                    }
                };
            }
        }

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', uuid)
            form.append('source', 'yysq')
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";
                    td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                tr = document.createElement("tr");td1 = document.createElement("td");td2 = document.createElement("td");td3 = document.createElement("td");td4 = document.createElement("td");td5 = document.createElement("td");td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i = 0; i < table.children.length; i++) {
                table.children[i].children[0].innerHTML = i + 1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id=" + String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }

        function save_data() {

            var fenshu = document.getElementById("fenshu").value;                   // 用印份数
            if (Quick === "true") {
                var yysy = document.getElementById("yysy").value;             // 用印事由
            }else {
                yysy = document.getElementById("yysy").innerText;
            }
            var selectButton_1 = document.getElementById("selectButton_1").innerText;       // 印章名称
            var note = document.getElementById('note').innerText;                       // 备注
            var credentials = document.getElementById('zjmc').value;            // 证件名称
            var reg = RegExp(/其他证书/);
            var leader_select = document.getElementById("leader_select").value;
            var FileType = document.getElementById("FileType").value;

            var YDetail = "";
            if (yysy === "其他") {
                YDetail = document.getElementById('YDetail').innerText;
            }

            var QuickApplication = $("input[type=radio][name=QuickApplication]:checked").val();
            var shouquan = []

            var data_str = "servings=" + fenshu + "&seal_name=" + selectButton_1 + "&credentials=" + credentials + "&matter_type_text=" + yysy + '&fj_number=' + String(uuid) + "&note=" + note+"&QuickApplication="+String(QuickApplication)+"&leader_select="+String(leader_select)+"&shouquan="+JSON.stringify(shouquan)+"&YDetail="+String(YDetail)+"&FileType="+FileType;

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/personal-center/seal_apply_draft_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send(data_str);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert(JsonDate["message"])
                            window.location.href = 'http://'+local_host+"/personal-center/seal_apply_list_view"
                        } else {
                            alert(JsonDate["message"])
                        }
                    }
                }
            };
        }

        function ExportCar() {
            var bgs_flag = '{{ bgs_flag | safe }}'
            var fenshu = document.getElementById("fenshu").value;                   // 用印份数
            if (Quick === "true") {
                var yysy = document.getElementById("yysy").value;             // 用印事由
            }else {
                yysy = document.getElementById("yysy").innerText;
            }
            var selectButton_1 = document.getElementById("selectButton_1").innerText;       // 印章名称
            var note = document.getElementById('note').innerText;                       // 备注
            var credentials = document.getElementById('zjmc').value;            // 证件名称
            var reg = RegExp(/其他证书/);
            var leader_select = document.getElementById("leader_select").value;
            var FileType = document.getElementById("FileType").value;
            var offline_printing = '';
            var YDetail = "";
            if (yysy === "其他") {
                YDetail = document.getElementById('YDetail').innerText;
                if (!YDetail) {
                    alert("请填写用印详情！")
                    return false
                }
            }

            if (selectButton_1.match(reg)){
                if (!credentials) {
                    alert('选择其他证书类型时,必须填写证件名称!!!')
                    return false
                }
            }

            if (FileType === "0") {
                alert('选择盖章文件类型!!!')
                return false
            }

            if (bgs_flag === 'true') {
                offline_printing = $("input[type=radio][name=offline]:checked").val();
            }

            var QuickApplication = $("input[type=radio][name=QuickApplication]:checked").val();
            var shouquan = []
            if (QuickApplication === 'yes') {
                var shouquantype_list = document.getElementsByClassName("shouquantype");
                for (var sq=0; sq<shouquantype_list.length; sq++) {
                    if (shouquantype_list[sq].checked) {
                        shouquan.push(shouquantype_list[sq].value)
                    }
                }
                if (!shouquan.length){
                    alert('请上传授权类型！')
                    return false
                }
            }else {
                if (!leader_select) {
                    alert('请选择分管领导!')
                    return false
                }
            }

            var data_str = "servings=" + fenshu + "&seal_name=" + selectButton_1 + "&credentials=" + credentials + "&matter_type_text=" + yysy + '&fj_number=' + String(uuid) + "&note=" + note+"&QuickApplication="+String(QuickApplication)+"&leader_select="+String(leader_select)+"&shouquan="+JSON.stringify(shouquan)+"&YDetail="+String(YDetail)+"&FileType="+FileType+"&offline_printing="+offline_printing;

            if (!fenshu || fenshu === '0') {
                alert("请填写用印份数！");
                return false
            }
            if (!selectButton_1) {
                alert("用印类型不能为空！");
                return false
            }
            if (!yysy) {
                alert('请填写用印事由！');
                return false
            }

            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/personal-center/seal_apply_index_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send(data_str);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("创建成功！")
                            window.location.href = 'http://'+local_host+"/personal-center/seal_apply_list_view"
                        } else {
                            alert(JsonDate["message"])
                        }
                    }
                }
            };
        }

        function del_adjunct_button() {
            document.getElementById("del_adjunct").style.display='none';
        }

        var seal_list = {{ seal_list | safe }};

        function shouquan_yes_no(types) {
            var selectdiv_1 = document.getElementById("selectdiv_1");
            selectdiv_1.innerHTML = "";
            if (types === '1'){
                for (var i=0; i<seal_all.length; i++) {
                    var input_tag = document.createElement("input");
                    input_tag.className = "check_anniu";input_tag.style.marginLeft="0.5%";input_tag.type="checkbox";
                    input_tag.value=seal_all[i]["seal_name"];input_tag.setAttribute("onclick", "mycheck1(this)");
                    var span_tag = document.createElement("span");span_tag.innerHTML=" " + seal_all[i]["seal_name"];
                    var br = document.createElement("br");
                    selectdiv_1.appendChild(input_tag);selectdiv_1.appendChild(span_tag);selectdiv_1.appendChild(br);
                }
                {#document.getElementById("shouquan_tr").style.display='table-row';#}
            }else {
                for (var t=0; t<seal_list.length; t++) {
                    var input_tag1 = document.createElement("input");
                    input_tag1.className = "check_anniu";input_tag1.style.marginLeft="0.5%";input_tag1.type="checkbox";
                    input_tag1.value=seal_list[t]["seal_name"];input_tag1.setAttribute("onclick", "mycheck1(this)");
                    var span_tag1 = document.createElement("span");span_tag1.innerHTML=" " + seal_list[t]["seal_name"];
                    var br1 = document.createElement("br");
                    selectdiv_1.appendChild(input_tag1);selectdiv_1.appendChild(span_tag1);selectdiv_1.appendChild(br1);
                }
                document.getElementById("shouquan_tr").style.display='none';
            }
        }

        function OrNotFill() {
            var fill_in = document.getElementById("yysy").value;
            if (fill_in === "其他") {
                document.getElementById("yy_detail").style.display="table-row";
            }else {
                document.getElementById("yy_detail").style.display="none";
            }
        }
    </script>
{% endblock %}
